﻿#ifndef APPCONFIG_H
#define APPCONFIG_H
#include "myhead.h"
#include <QObject>
#include <QSettings>

struct TcpCfg
{
    QString address;
    int timeout;
};

struct SerialPortParam
{
    SerialPortParam()
    {
        comName="COM1";
        baudRate="4800";
        dataBits="Data5";
        stopBits="OneStop";
        parity="NoPraity";
        flowControl="NoFlowControl";
    }

    QString comName;
    QString baudRate;
    QString dataBits;
    QString stopBits;
    QString parity;
    QString flowControl;
};

struct RequestCfg
{
    bool isSave;
    bool isHex;
    QString curCmd;
};

class CommConfig
{
private:
    CommConfig();
    virtual ~CommConfig();
    CommConfig(const CommConfig&) = delete;
    CommConfig& operator=(const CommConfig&) = delete;

public:
    static CommConfig& instance();

    TcpCfg getTcpCfg(QString groupName);
    void setTcpCfg(QString groupName, const TcpCfg &cfg);

    SerialPortParam getSerialPortCfg(QString groupName);
    void setSerialPortCfg(QString groupName, const SerialPortParam &cfg);

    RequestCfg getReqCfg(QString groupName);
    void setReqCfg(QString groupName, const RequestCfg &cfg);
private:
    QSettings *_set=nullptr;
    static bool copyResourceToFile(const QString &resourcePath, const QString &destinationPath);
};

#endif // APPCONFIG_H
